/*
 *  Name		: ADC_api.c
 *	Author	 	: Tigran Papazyan
 *  Created on	: Dec 6, 2010
 *  Copyright   : Copyright Antel Systems
 *  Description : ADC application
 */

#include "compiler.h"
#include "board.h"
#include "gpio.h"
#include "adc.h"
#include "ADC_api.h"

volatile avr32_adc_t *adc = &AVR32_ADC; // ADC IP registers address

void ADC_Init(void)
{
	static const gpio_map_t ADC_GPIO_MAP =
	{
	{PWRSRC_ADC_INPUT_PIN, PWRSRC_ADC_INPUT_FUNCTION}
	};

	gpio_enable_module(ADC_GPIO_MAP, sizeof(ADC_GPIO_MAP) / sizeof(ADC_GPIO_MAP[0]));

	AVR32_ADC.mr |= 0x1 << AVR32_ADC_MR_PRESCAL_OFFSET;
	adc_configure(adc);

	adc_enable(adc,PWRSRC_ADC_CHANNEL);
	adc_start(adc);
}

signed short ADC_0_Get(void)
{
	signed short adc_value_temp = -1;
	adc_value_temp = adc_get_value(adc, PWRSRC_ADC_CHANNEL);
	adc_start(adc);
	return adc_value_temp ;
}

